import java.util.Stack;


public class PostFixe {
	private String m;
	
	public PostFixe(String m) { this.m = m; }
	
	public int Eval() {
		String n = m;
		String x = getX(n);
		
		if(n.length() > x.length())
		{
			n = n.substring(x.length()+1);
		}
		else
		{
			n = "";
		}
		
		Stack<String> pile = new Stack<String>();
		
		while(!x.isEmpty())
		{
			if(isOperator(x.charAt(0)))
			{
				int b2 = toInt(pile.pop());
				int b1 = toInt(pile.pop());
				
				pile.push(""+doOperation(b1, x, b2));
			}
			else
			{
				pile.push(x);
			}
			
			x = getX(n);
			
			if(n.length() > x.length())
			{
				n = n.substring(x.length()+1);
			}
			else
			{
				n = "";
			}
		}
		
		return toInt(pile.pop());
	}

	private int doOperation(int b1, String x, int b2) {
		int res = 0;
		
		if(x.equals("*"))
		{
			res = b1 * b2;
		}
		else if(x.equals("+"))
		{
			res = b1 + b2;
		}
		else if(x.equals("-"))
		{
			res = b1 - b2;
		}
		else if(x.equals("/"))
		{
			res = b1 / b2;
		}
		
		return res;
	}

	private int toInt(String x) {
		return Integer.parseInt(x);
		/*int n = 0;
		int k = 0;
		
		while(k < x.length())
		{
			n += (k*10* (x.charAt(k) - '0') );
			
			k++;
		}
		
		return n;*/
	}

	private boolean isOperator(char x) {
		return (x == '+' || x == '/' || x == '*' || x == '-');
	}

	private String getX(String n) {
		String x = "";
		int k = 0;
		
		while(k < n.length() && n.charAt(k) != ' ')
		{
			x = x + n.charAt(k);
			k++;
		}
		
		return x;
	}
}
